#!/usr/bin/python
# -*- coding: utf-8 -*-

import sys, os
import Ice, IceStorm

try:
    HOME = os.environ['ROBOTS']
except KeyError:
    print 'ROBOTS environment variable is not currently defined.'
    sys.exit(0)

SLICE = os.path.join(HOME, 'slice')
FILE = os.path.join(SLICE, 'Robots.ice')
SRC = os.path.join(HOME, 'src')
sys.path.append(SRC)
Ice.loadSlice('--all -I/usr/share/slice', ['-I' + SLICE, FILE])

import Robots
import AgentI
from AgentI import *

class Server (Ice.Application):

    def run (self, argv):
        self.shutdownOnInterrupt()

        adapter = self.communicator().createObjectAdapterWithEndpoints('Adapter', 'default -p 9898')
        id1 = adapter.getCommunicator().stringToIdentity('A')
        id2 = adapter.getCommunicator().stringToIdentity('B')
        id3 = adapter.getCommunicator().stringToIdentity('C')
        id4 = adapter.getCommunicator().stringToIdentity('D')
        id5 = adapter.getCommunicator().stringToIdentity('E')
        adapter.add(AgentI(id1, 'X', '', adapter), id1)
        adapter.add(AgentI(id2, 'X', '', adapter), id2)
        adapter.add(AgentI(id3, 'X', '', adapter), id3)
        adapter.add(AgentI(id4, 'X', '', adapter), id4)
        #adapter.add(AgentI(id5, 'X', '', adapter), id5)
        adapter.activate()

        self.communicator().waitForShutdown();
        return 0

Server().main(sys.argv, 'config.server')
